package com.yylending.las.common.utils;

import com.yylending.las.lending.process.chooseamount.ChooseAmountModel;

/**
 * Created by fan on 2017/6/26.
 * Copyright  2017 www.yylending.com. All Rights Reserved.
 */
public class AmountUtils {

	/**
	 * 综合费用
	 * @param loanAmount 借款金额
	 * @param onceFeeRate 一次性费率
	 * @return
	 */
	public static String getComprehensiveCost(int loanAmount, String onceFeeRate) {
		double comprehensiveCost = getComprehensiveCost(loanAmount, Double.valueOf(onceFeeRate));
		return FormatUtils.formatNumTwo(comprehensiveCost);
	}

	/**
	 * 综合费用
	 * @param loanAmount 借款金额
	 * @param onceFeeRate
	 * @return
	 */
	public static Double getComprehensiveCost(int loanAmount, double onceFeeRate) {
		return loanAmount*onceFeeRate;
	}

	/**
	 * 到账金额
	 * @param loanAmount 借款金额
	 * @param comprehensiveCost 综合费用
	 * @return
	 */
	public static String getActualToAccount(int loanAmount, String comprehensiveCost) {
		double actualToAccount = getActualToAccount(loanAmount, Double.valueOf(comprehensiveCost));
		return FormatUtils.formatNumTwo(actualToAccount);
	}

	/**
	 * 到账金额
	 * @param loanAmount 借款金额
	 * @param comprehensiveCost 综合费用
	 * @return
	 */
	public static double getActualToAccount(int loanAmount, double comprehensiveCost) {
		return loanAmount-comprehensiveCost;
	}

	/**
	 * 每月应还
	 * @param rate 利率对象
	 * @param loanAmount 借款金额
	 * @param loanTerm 还款期数
	 * @return
	 */
	public static String getTerminallyRepayment(ChooseAmountModel.Rate rate,int loanAmount, int loanTerm) {
		//月利率
		double businessRateMonth=Float.valueOf(rate.businessRate)/12;
		double pow = Math.pow((1 + businessRateMonth), loanTerm);
		double terminallyRepayment= (loanAmount*businessRateMonth*pow)/(pow-1)+loanAmount*Float.valueOf(rate.integratedRate);
		return FormatUtils.formatNumTwo(terminallyRepayment);
	}

}
